package com.imooc.coupon.advice;

import com.imooc.coupon.exception.CouponException;
import com.imooc.coupon.vo.CommonResponse;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

import javax.servlet.http.HttpServletRequest;

/**  全局异常增强
 * @description:
 * @author：naxiaozi，微信：naxiaozi
 * @date: 2025/8/9
 * @Copyright：
 */
@RestControllerAdvice
public class GlobalExceptionAdvice {
    @ExceptionHandler(value = CouponException.class)
    public CommonResponse<String> handlerCouponException(
            HttpServletRequest req, CouponException ex){
        CommonResponse<String> response = new CommonResponse<>(
                -1,"business error"
        );
        response.setData(ex.getLocalizedMessage());
        return response;
    }
}
